<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <h2 id="counter">0</h2>
    <button id="increment">+1</button>
    <button id="decrement">-1</button>

    <script>
      // 1.获取元素
      let counterEl = document.querySelector('#counter')
      let increment = document.querySelector('#increment')
      let decrement = document.querySelector('#decrement')

      // 2.定义变量
      let counter = 100
      counterEl.innerHTML = counter

      // 3.监听按钮点击事件
      increment.addEventListener('click', function () {
        counter++
        counterEl.innerHTML = counter
      })
      decrement.addEventListener('click', function () {
        counter--
        counterEl.innerHTML = counter
      })
    </script>
  </body>
</html>
